import { createRouter, createWebHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";

const routes = [
  {
    path: "/",
    redirect: "/home/singUp",
  },
  {
    path: "/home",
    name: "home",
    component: HomeView,
    children: [
      {
        path: "singUp",
        name: "singUp",
        component: () => import("../views/SingUp/SingUp.vue")
      },
      {
        path: "liveIndex",
        name: "liveIndex",
        redirect: 'liveIndex/Class',
        component: () => import("../views/LiveClass/LiveIndex.vue"),
        children: [
          {
            path: 'Class',
            name: 'Class',
            component: () => import("../views/LiveClass/LiveClass.vue")
          },
          {
            path: 'Info',
            name: 'Info',
            component: () => import("../views/LiveClass/LiveInfo.vue")
          }
        ]
      },
      {
        path: "liveClassOne/:id",
        name: "liveClassOne",
        component: () => import("../views/LiveClass/LiveClassOne.vue"),

      },
      {
        path: "liveClassSon/:id",
        name: "liveClassSon",
        component: () => import("../views/LiveClass/LiveClassSon.vue"),

      },
      {
        path: "liveClassComment/:id",
        name: "liveClassComment",
        component: () => import("../views/LiveClass/LiveClassComment.vue"),
      },
      {
        path: "liveInfoSon/:id",
        name: "liveInfoSon",
        component: () => import("../views/LiveClass/LiveInfoSon.vue")
      },
      {
        path: "liveClassRule",
        name: "liveClassRule",
        component: () => import("../views/LiveClass/LiveClassRule.vue"),
      },
      {
        path: "LiveClassOneMe/:id",
        name: "liveClassOneme",
        component: () => import("../views/LiveClass/LiveClassOneMe.vue"),
      },
      {
        path: "test",
        name: "test",
        component: () => import("../views/Test/Test.vue")
      },
      {
        path: "me",
        name: "me",
        component: () => import("../views/Me/Me.vue")
      },

      {
        path: "TestKao/:id",
        name: "TestKao",
        component: () => import("../views/Test/TestKao.vue")
      },
      {
        path: "CuoTi/:id",
        name: "CuoTi",
        component: () => import("../views/Test/CuoTi.vue")
      },
      {
        path: "TestLian/:id",
        name: "TestLian",
        component: () => import("../views/Test/TestLian.vue")
      },
    ],

  },
  
  {//搜索路由
    path: "/search",
    name: "search",
    component: () => import("../views/SingUp/Search.vue"),
  },
  {
    path: "/cartMap",
    name: "cartMap",
    component: () => import("../views/SingUp/CartMap.vue"),
  },
  {
    path: "/about",
    name: "about",
    component: () => import("../views/AboutView.vue"),
  },
  {
    path: "/schoolDetails/:schoolId",
    name: "schoolDetails",
    component: () => import("../views/SingUp/SchoolDetails.vue"),
  },
  {
    path: "/SchoolRanking",
    name: "SchoolRanking",
    component: () => import("../views/SingUp/ranking/SchoolRanking.vue"),
  },
  {
    path: "/coachRanking",
    name: "coachRanking",
    component: () => import("../views/SingUp/ranking/coachRanking.vue"),
  },
  {
    path: "/MeNext",
    name: "MeNext",
    component: () => import("../views/Me/MeNext.vue")
  },
  {
    path: "/Setup",
    name: "Setup",
    component: () => import("../views/Me/Setup.vue")
  },
  {
    path: "/news",
    name: "news",
    component: () => import("../views/Me/news.vue")
  },
  {
    path: "/Mecipher",
    name: "Mecipher",
    component: () => import("../views/Me/Mechild/Mecipher.vue")
  },
  

  // 临时查看组件
  {
    path: "/cp/:id",
    name: "cp",
    component: () => import("../views/ComPon/ComPon.vue"),
  },
  {
    path: '/user/login',
    name: 'login',
    component: () => import('../views/User/Login.vue'),
  }
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});


// 添加全局前置守卫 
import store from '@/store'
router.beforeEach((to, from, next) => {
  if (to.path == '/user/login' || store.state.user) {
    next()
  }else {
    router.push('/user/login')
  }
})

export default router;
